package com.shop2cn.iapi.payment.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.payment.parameter.CatalogQueryDto;
import com.shop2cn.iapi.payment.parameter.QueryPayCompanyBean;
import com.shop2cn.iapi.payment.service.QueryPayCompanyCall;
import com.ymatou.iapi.godmch.parameter.setShareTypeBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.utils.TestDataManager;
/**
*查询第三方支付公司
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryPayCompany{
	private static QueryPayCompanyBean querypaycompanyBean;
	private static QueryPayCompanyCall querypaycompanyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询第三方支付公司");
	}

	@Before
	public void caseUp() {
		querypaycompanyBean=new QueryPayCompanyBean();
		querypaycompanyCall=new QueryPayCompanyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querypaycompanyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryPayCompany_001() {
		Logger.start(true,"查询第三方支付公司,成功-isDomestic-false为1");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			setShareTypeBean bean=new setShareTypeBean();
			bean.setAliPayMode(0);
			bean.setDualMode(0);
			bean.setMchId(mchId_channl);
			bean.setMchShareType(1);
			bean.setPayMode(1);
			bean.setMchSideBuy(1);
			bean.setDomesticPayMode(1);
			GodmchManageCallService.setShareTypeV2Call(bean);
			
			
			List<CatalogQueryDto> catalogs=new ArrayList<CatalogQueryDto>();
			CatalogQueryDto e=new CatalogQueryDto();
			e.setCatalogId(TestDataManager.getRandomUUID().toString());
			e.setDomestic(false);
			e.setRootSellerId(mchId_channl);
			catalogs.add(e);
			querypaycompanyBean.setCatalogs(catalogs);
			querypaycompanyCall.setData(querypaycompanyBean);
			querypaycompanyCall.callService();			
			Logger.verifyEquals("200", querypaycompanyCall.getString("code"), "验证code");
			Map<String ,Integer> mdata=new HashMap<String ,Integer>();
			querypaycompanyCall.getJsonObject().get("data").getAsJsonArray().forEach(d->{
				mdata.put(d.getAsJsonObject().get("catalogId").getAsString(), d.getAsJsonObject().get("payCompany").getAsInt());
			});
			Logger.verifyEquals(1, mdata.get(e.getCatalogId()), "验证payCompany");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryPayCompany_002() {
		Logger.start(true,"不输入catalogs失败");
		try {
//			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
//			setShareTypeBean bean=new setShareTypeBean();
//			bean.setAliPayMode(0);
//			bean.setDualMode(0);
//			bean.setMchId(mchId_channl);
//			bean.setMchShareType(1);
//			bean.setPayMode(1);
//			bean.setMchSideBuy(1);
//			bean.setDomesticPayMode(1);
//			GodmchManageCallService.setShareTypeV2Call(bean);
			
			
//			List<CatalogQueryDto> catalogs=new ArrayList<CatalogQueryDto>();
//			CatalogQueryDto e=new CatalogQueryDto();
//			e.setCatalogId(TestDataManager.getRandomUUID().toString());
//			e.setIsDomestic(false);
//			e.setRootSellerId(mchId_channl);
//			catalogs.add(e);
//			querypaycompanyBean.setCatalogs(catalogs);
			querypaycompanyCall.setData(querypaycompanyBean);
			querypaycompanyCall.callService();			
			Logger.verifyEquals("400", querypaycompanyCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryPayCompany_003() {
		Logger.start(true,"输入不存在rootSellerId失败");
		try {
			List<CatalogQueryDto> catalogs=new ArrayList<CatalogQueryDto>();
			CatalogQueryDto e=new CatalogQueryDto();
			e.setCatalogId(TestDataManager.getRandomUUID().toString());
			e.setDomestic(true);
			e.setRootSellerId(-1);
			catalogs.add(e);
			querypaycompanyBean.setCatalogs(catalogs);
			querypaycompanyCall.setData(querypaycompanyBean);
			querypaycompanyCall.callService();			
			Logger.verifyEquals("300", querypaycompanyCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryPayCompany_004() {
		Logger.start(true,"商户没开sft和双通道-isDomestic-true返回为1");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			setShareTypeBean bean=new setShareTypeBean();
			bean.setAliPayMode(0);
			bean.setDualMode(0);
			bean.setMchId(mchId_channl);
			bean.setMchShareType(1);
			bean.setPayMode(1);
			bean.setMchSideBuy(1);
			bean.setDomesticPayMode(0);
			GodmchManageCallService.setShareTypeV2Call(bean);
			
			
			List<CatalogQueryDto> catalogs=new ArrayList<CatalogQueryDto>();
			CatalogQueryDto e=new CatalogQueryDto();
			e.setCatalogId(TestDataManager.getRandomUUID().toString());
			e.setDomestic(true);
			e.setRootSellerId(mchId_channl);
			catalogs.add(e);
			querypaycompanyBean.setCatalogs(catalogs);
			querypaycompanyCall.setData(querypaycompanyBean);
			querypaycompanyCall.callService();			
			Logger.verifyEquals("200", querypaycompanyCall.getString("code"), "验证code");
			Map<String ,Integer> mdata=new HashMap<String ,Integer>();
			querypaycompanyCall.getJsonObject().get("data").getAsJsonArray().forEach(d->{
				mdata.put(d.getAsJsonObject().get("catalogId").getAsString(), d.getAsJsonObject().get("payCompany").getAsInt());
			});
			Logger.verifyEquals(1, mdata.get(e.getCatalogId()), "验证payCompany");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryPayCompany_005() {
		Logger.start(true,"商户开了sft-isDomestic-true返回为2");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			setShareTypeBean bean=new setShareTypeBean();
			bean.setAliPayMode(0);
			bean.setDualMode(0);
			bean.setMchId(mchId_channl);
			bean.setMchShareType(1);
			bean.setPayMode(1);
			bean.setMchSideBuy(1);
			bean.setDomesticPayMode(1);
			GodmchManageCallService.setShareTypeV2Call(bean);
//			Thread.sleep(2000);
			
			List<CatalogQueryDto> catalogs=new ArrayList<CatalogQueryDto>();
			CatalogQueryDto e=new CatalogQueryDto();
			e.setCatalogId(TestDataManager.getRandomUUID().toString());
			e.setDomestic(true);
			e.setRootSellerId(mchId_channl);
			catalogs.add(e);
			querypaycompanyBean.setCatalogs(catalogs);
			querypaycompanyCall.setData(querypaycompanyBean);
			querypaycompanyCall.callService();			
			Logger.verifyEquals("200", querypaycompanyCall.getString("code"), "验证code");
			Map<String ,Integer> mdata=new HashMap<String ,Integer>();
			querypaycompanyCall.getJsonObject().get("data").getAsJsonArray().forEach(d->{
				mdata.put(d.getAsJsonObject().get("catalogId").getAsString(), d.getAsJsonObject().get("payCompany").getAsInt());
			});
			Logger.verifyEquals(2, mdata.get(e.getCatalogId()), "验证payCompany");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryPayCompany_006() {
		Logger.start(true,"商户开了双通道-isDomestic-true返回为2");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			setShareTypeBean bean=new setShareTypeBean();
			bean.setAliPayMode(0);
			bean.setDualMode(1);
			bean.setMchId(mchId_channl);
			bean.setMchShareType(1);
			bean.setPayMode(1);
			bean.setMchSideBuy(1);
			bean.setDomesticPayMode(0);
			GodmchManageCallService.setShareTypeV2Call(bean);
			HashMap<String,Object> map=new HashMap();
			map.put("mchId", bean.getMchId());
		     mch_info act_info=new mch_infoWapper().selectby(map).get(0);
		     Logger.debug(FormatUtil.beanToGSONString(act_info));
//			Thread.sleep(2000);
			
			List<CatalogQueryDto> catalogs=new ArrayList<CatalogQueryDto>();
			CatalogQueryDto e=new CatalogQueryDto();
			e.setCatalogId(TestDataManager.getRandomUUID().toString());
			e.setDomestic(true);
			e.setRootSellerId(mchId_channl);
			catalogs.add(e);
			querypaycompanyBean.setCatalogs(catalogs);
			querypaycompanyCall.setData(querypaycompanyBean);
			querypaycompanyCall.callService();			
			Logger.verifyEquals("200", querypaycompanyCall.getString("code"), "验证code");
			Map<String ,Integer> mdata=new HashMap<String ,Integer>();
			querypaycompanyCall.getJsonObject().get("data").getAsJsonArray().forEach(d->{
				mdata.put(d.getAsJsonObject().get("catalogId").getAsString(), d.getAsJsonObject().get("payCompany").getAsInt());
			});
			Logger.verifyEquals(2, mdata.get(e.getCatalogId()), "验证payCompany");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryPayCompany_007() {
		Logger.start(true,"查询第三方支付公司,多个结果成功");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			setShareTypeBean bean=new setShareTypeBean();
			bean.setAliPayMode(0);
			bean.setDualMode(0);
			bean.setMchId(mchId_channl);
			bean.setMchShareType(1);
			bean.setPayMode(1);
			bean.setMchSideBuy(1);
			bean.setDomesticPayMode(1);
			GodmchManageCallService.setShareTypeV2Call(bean);
			
			Integer mchId_channl2 = GodmchManageCallService.CreateSellerMch();
			bean.setAliPayMode(0);
			bean.setDualMode(0);
			bean.setMchId(mchId_channl2);
			bean.setMchShareType(1);
			bean.setPayMode(1);
			bean.setMchSideBuy(1);
			bean.setDomesticPayMode(1);
			GodmchManageCallService.setShareTypeV2Call(bean);
			
			List<CatalogQueryDto> catalogs=new ArrayList<CatalogQueryDto>();
			CatalogQueryDto e=new CatalogQueryDto();
			e.setCatalogId(TestDataManager.getRandomUUID().toString());
			e.setDomestic(true);
			e.setRootSellerId(mchId_channl);
			catalogs.add(e);
			CatalogQueryDto e2=new CatalogQueryDto();
			e2.setCatalogId(TestDataManager.getRandomUUID().toString());
			e2.setDomestic(false);
			e2.setRootSellerId(mchId_channl2);
			catalogs.add(e2);
			
			querypaycompanyBean.setCatalogs(catalogs);
			querypaycompanyCall.setData(querypaycompanyBean);
			querypaycompanyCall.callService();			
			Logger.verifyEquals("200", querypaycompanyCall.getString("code"), "验证code");
			Map<String ,Integer> mdata=new HashMap<String ,Integer>();
			querypaycompanyCall.getJsonObject().get("data").getAsJsonArray().forEach(d->{
				mdata.put(d.getAsJsonObject().get("catalogId").getAsString(), d.getAsJsonObject().get("payCompany").getAsInt());
			});
			Logger.verifyEquals(2, mdata.get(e.getCatalogId()), "验证payCompany");	
			Logger.verifyEquals(1, mdata.get(e2.getCatalogId()), "验证payCompany");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryPayCompany_008() {
		Logger.start(true,"输入catalogs数据为空失败");
		try {
			querypaycompanyBean.setCatalogs(new ArrayList<CatalogQueryDto>());
			querypaycompanyCall.setData(querypaycompanyBean);
			querypaycompanyCall.callService();			
			Logger.verifyEquals("400", querypaycompanyCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}